﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace c2iGMailNotifier
{
    public class UIManager
    {
        private static readonly UIManager Instance = new UIManager();
        private readonly Dictionary<string, ViewDefinition> _uiElementDefinitions = new Dictionary<string, ViewDefinition>();

        public static void RegisterView(string viewKey, string regionKey, string typeName)
        {
            RegisterView(viewKey, regionKey, Type.GetType(typeName));
        }

        public static void RegisterView(string viewKey, string regionKey, Type viewType)
        {
            if (viewKey == null)
                throw new ArgumentNullException("viewKey", "La clé ne peut être null");
            if (viewType == null)
                throw new ArgumentNullException("viewType", "Le type de la view ne peut être null");

            Instance._uiElementDefinitions.Add(viewKey, new ViewDefinition(regionKey, viewType));
        }

        public static UIElement GetView(string viewKey)
        {
            return Instance._uiElementDefinitions[viewKey].GetInstance();
        }

        public static ViewDefinition GetViewDefinition(string viewKey)
        {
            return Instance._uiElementDefinitions[viewKey];
        }
    }
}